package personal.lijun.skeleton.springcloud.serviceprovider.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import personal.lijun.skeleton.spring.springcloud.serviceprovider.data.SecurityFiltermetadata;
import personal.lijun.skeleton.spring.springcloud.serviceprovider.service.SecurityFiltermetadataService;
import personal.lijun.skeleton.springcloud.dataaccess.dao.SecurityFiltermetadataMapper;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther: lijun@sstcsoft.com
 * @Date: 2019/9/18 14:29
 */
@Service("SecurityFiltermetadataService")
public class SecurityFiltermetadataServiceImp implements SecurityFiltermetadataService {

    @Autowired
    private SecurityFiltermetadataMapper securityFiltermetadataMapper;
    /**
     * 查询所有菜单权限
     *
     * @return
     */
    @Override
    public List<SecurityFiltermetadata> getRequestConfigMappings() {
        List<personal.lijun.skeleton.springcloud.dataaccess.data.SecurityFiltermetadata> dbsecurityFiltermetadataList
                = securityFiltermetadataMapper.selectByExample(null);
        List<SecurityFiltermetadata> retList = new ArrayList<>(dbsecurityFiltermetadataList.size());
        SecurityFiltermetadata sfmData;
        personal.lijun.skeleton.springcloud.dataaccess.data.SecurityFiltermetadata dbSfmData;
        for(int i=0;i<dbsecurityFiltermetadataList.size();i++){
            dbSfmData = dbsecurityFiltermetadataList.get(i);
            sfmData = new SecurityFiltermetadata();
            BeanUtils.copyProperties(dbSfmData,sfmData);
            dbsecurityFiltermetadataList.set(i,null);
            retList.add(sfmData);
        }
        return retList.stream().sorted(Comparator.comparingInt(SecurityFiltermetadata::getSortOrder)).collect(Collectors.toList());
    }
}
